In [1]:
import matplotlib.pyplot as plt
import pandas as pd
from pandas.tools.plotting import table
import numpy as np

%matplotlib inline

dataframe to png ( image )


In [44]:
plt.clf() # clear
ax = plt.subplot(111, frame_on=False) # visible frame option false
ax.xaxis.set_visible(False)  # hide the x axis
ax.yaxis.set_visible(False)  # hide the y axis

df = pd.DataFrame(np.random.randn(10,5)) # make random dataframe

table(ax, df) 

plt.savefig('./image/mytable.png')


/usr/local/lib/python3.6/site-packages/ipykernel_launcher.py:8: FutureWarning: 'pandas.tools.plotting.table' is deprecated, import 'pandas.plotting.table' instead.
  

insert image in pandas dataframe ( to html )


In [2]:
from IPython.display import HTML
df = pd.DataFrame({'A': np.linspace(1, 3, 3)})
df['image'] = 'retrica.png'
df.iloc[2,1] = 'retrica_1.png'
df['new'] = df['image'].apply(lambda x: '<img src="./image/{}" width="80%" height="80%"/>'.format(x) if x else '')


def hover(hover_color="#ffff99"):
    return dict(selector="tr:hover",
                props=[("background-color", "%s" % hover_color)])

styles = [
    hover(),
    dict(selector="th", props=[("font-size", "150%"),
                               ("text-align", "center")]),
    dict(selector="caption", props=[("caption-side", "bottom")])
]
html = (df.style.set_table_styles(styles)
          .set_caption("Hover to highlight."))

html


Out[2]:
Hover to highlight.
A image new
0 1 retrica.png
1 2 retrica.png
2 3 retrica_1.png

In [43]:
df


Out[43]:
A image new
0 1.0 retrica.png <img src="retrica.png"/>
1 2.0 retrica.png <img src="retrica.png"/>
2 3.0 retrica_1.png <img src="retrica_1.png"/>

In [ ]:
def sticker_img(name):
    if 'Sticker' in name:
        return '<img src="./img/{}.png" width="10%" height="10%"/>'.format(name) if name else ''
    else:
        return change_dict.get(name, name)

In [ ]:
sticker_df['sticker_name'] = sticker_df['sticker'].apply(lambda x: sticker_img(x))